cmake_minimum_required(VERSION 3.16)

project(plugin_config LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#设置输出目录为 ../../output（相对于构建目录）
# set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/../output/")
file(MAKE_DIRECTORY ${OUTPUT_DIR})  # 确保目录存在
message(STATUS "Final output path: ${OUTPUT_DIR}")
# 关键修改1: 明确查找 Core + Widgets 模块
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets SerialPort)       # 修改点1
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets SerialPort) # 修改点2

add_library(plugin_config SHARED
  plugin_config.cpp
  plugin_config.h
  plugin_config.json
  ../../IPlugin.h
  plugin_config.ui
  config_addstyle.h config_addstyle.cpp config_addstyle.ui
  config_infoset.h config_infoset.cpp config_infoset.ui
  ../../../maxtool/LineEdit/customlineedit.h
  ../../../maxtool/LineEdit/customlineedit.cpp

)

# 设置动态库输出路径（兼容Windows/Linux）
set_target_properties(plugin_config PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # Linux的.so文件路径
  RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # Windows的.dll文件路径
  ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # 静态库（可选）
)
# 关键修改2: 添加头文件搜索路径
target_include_directories(plugin_config PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/../..  # 确保能找到 ../../IPlugin.h
  ${CMAKE_CURRENT_SOURCE_DIR}/../../../maxtool
)
# 关键修改3: 链接 Qt Widgets 模块
target_link_libraries(plugin_config PRIVATE
  Qt${QT_VERSION_MAJOR}::Core
  Qt${QT_VERSION_MAJOR}::Widgets
  Qt${QT_VERSION_MAJOR}::SerialPort
)


